//
//  NBCFoundationUtils.h
//  KDExample
//
//  Created by 叶青 on 2017/3/7.
//  Copyright © 2017年 naruto. All rights reserved.
//  公用的定义

#ifndef NBCFoundationUtils_h
#define NBCFoundationUtils_h


#import <objc/message.h>
#import <Foundation/Foundation.h>

//屏幕宽度
#define kBCSCREEN_WIDTH             [UIScreen mainScreen].bounds.size.width
//屏幕高度
#define kBCSCREEN_HEIGHT            [UIScreen mainScreen].bounds.size.height
//屏幕高度
#define kBCAPP_HEIGHT               [UIScreen mainScreen].applicationFrame.size.height
//tab bar高度
#define kBCTABBAR_HEIGHT            48
//nav bar 高度
#define kBCNAVBAR_HEIGHT            64

#define kBCAppDelegate              [[UIApplication sharedApplication] keyWindow]


#pragma mark - 文件相关
/**
 获取document 目录下的文件路径
 
 @param filename 文件名
 @return 文件路径
 */
static inline NSString *BCDocumentFilePath(NSString *filename) {
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentsDirectory = [paths objectAtIndex:0];
    NSString *path = [documentsDirectory stringByAppendingPathComponent:filename];
    return path;
}


#pragma mark - log


#ifdef DEBUG

#define     BCLog(...)                  NSLog(__VA_ARGS__)
#define     BCLogInfo(format, ...)      NSLog((@"%s:%d|"format), __FUNCTION__, __LINE__, ##__VA_ARGS__)

#else

#define     BCLogInfo(...)
#define     BCLog(...)

#endif

#define     BCLogDealloc()              BCLog(@"%@ dealloc",NSStringFromClass([self class]));

#define     BCWeakObj(obj)              autoreleasepool{} __weak typeof(obj) obj##Weak = obj
#define     BCStrongObj(obj)            autoreleasepool{} __strong typeof(obj) obj = obj##Weak

#pragma mark - runtime

#define BCObjcClass(clsname)                    objc_getClass(clsname)

#define BCObjectClass(clsname)                  object_getClass(clsname)

#define BCSelector(selname)                     NSSelectorFromString(selname)


#define BCInstanceInfo(cls) \
do{\
    unsigned int count = 0;\
    NSLog(@"#############################");\
    NSLog(@"%@ property list",cls);\
    objc_property_t *propertyList = class_copyPropertyList(cls, &count);\
    for (NSInteger i = 0; i<count; i++) {\
        const char *propertyName = property_getName(propertyList[i]);\
        NSLog(@"%@", [NSString stringWithUTF8String:propertyName]);\
    }\
    NSLog(@"#############################");\
    NSLog(@"%@ method list",cls);\
    Method *methodList = class_copyMethodList(cls, &count);\
    for (int i = 0; i<count; i++) {\
        Method method = methodList[i];\
        NSLog(@"%@", NSStringFromSelector(method_getName(method)));\
    }\
    NSLog(@"#############################");\
    NSLog(@"%@ Ivar list",cls);\
    Ivar *ivarList = class_copyIvarList(cls, &count);\
    for (int i = 0; i<count; i++) {\
        Ivar ivar = ivarList[i];\
        const char *ivarName = ivar_getName(ivar);\
        NSLog(@"%@", [NSString stringWithUTF8String:ivarName]);\
    }\
}while(0)

#endif /* NBCFoundationUtils_h */
